package com.nie.orderfood.convertor;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nie.orderfood.DTO.OrderMasterDTO;
import com.nie.orderfood.entity.OrderDetail;
import com.nie.orderfood.form.OrderForm;

import java.util.List;

/**
 * @program: orderfood
 * @description: orderform转换成ordermaster转换器
 * @author: NieMiao
 * @create: 2018-10-15 17:22
 **/
public class Orderform2OrderMasterDTOConvertor {
    public static OrderMasterDTO convert(OrderForm orderForm) {
        Gson gson = new Gson();

        OrderMasterDTO orderMasterDTO = new OrderMasterDTO();
        orderMasterDTO.setBuyerName(orderForm.getName());
        orderMasterDTO.setBuyerPhone(orderForm.getPhone());
        orderMasterDTO.setBuyerAddress(orderForm.getAddress());
        orderMasterDTO.setBuyerOpenid("ew3euwhd7sjw9diwkq");

        List<OrderDetail> orderDetailList = gson.fromJson(orderForm.getItems(),
                new TypeToken<List<OrderDetail>>(){}.getType());
        orderMasterDTO.setOrderDetailList(orderDetailList);
        return orderMasterDTO;
    }
}
